Calling this[int index] via reflection
        Posted  
        
            by 
                tkutter
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by tkutter
        
        
        
        Published on 2012-10-31T11:15:06Z
        Indexed on 
            2012/11/01
            17:01 UTC
        
        
        Read the original article
        Hit count: 278
        
I try to implement a reflection-based late-bound library to Microsoft Office. The properties and methods of the Offce COM objects are called the following way:
Type type = Type.GetTypeFromProgID("Word.Application");
object comObject = Activator.CreateInstance(type);
type.InvokeMember(<METHOD NAME>, <BINDING FLAGS>, null, comObject, new object[] { <PARAMS>});
InvokeMember is the only possible way because Type.GetMethod / GetProperty works improperly with the COM objects.
Methods and properties can be called using InvokeMember but now I have to solve the following problem:
Method in the office-interop wrapper:
Excel.Workbooks wb = excel.Workbooks;
Excel.Workbook firstWb = wb[0];
respectively
foreach(Excel.Workbook w in excel.Workbooks)
  // doSmth. 
How can I call the this[int index] operator of Excel.Workbooks via reflection?
© Stack Overflow or respective owner